<?php
class User extends AppModel {
	var $name = "User";
	var $validate = array(
		'username' => array(
			'rule' => 'notEmpty'
		),
		'password' => array(
			'rule' => 'notEmpty'
		),
		'Name' => array(
			'rule' => 'notEmpty'
		)
	);
		
	function validateLogin($data) { 
        $user = $this->find(array('username' => $data['username'], 'password' => Security::hash($data['password'])), array('id', 'username')); 
        if(empty($user) == false) 
            return $user['User']; 
        return false; 
    } 
    
	function beforeSave() {
       /*if ($this->data['User']['password']) {
       		$this->data['User']['password'] = $this->Auth->password($this->data['User']['password']);
            //$this->data['User']['password'] = Security::hash($this->data['User']['password']);
       }*/
       return true;
  	}
  	
	function hashPasswords($data) { 
		if (isset($data['User']['password'])) {                
			$data['User']['password'] = $this->Auth->password($data['User']['password']);
			//$data['User']['password'] = Security::hash($data['User']['password']);            
			return $data;        
		}        
		return $data;    
	}
	
	function isAuthorized() {
            return true; 
    }
	
}